@extends('admin.common.main')
@section('cnt')

    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span> 房源管理
        <span class="c-gray en">&gt;</span> 预约列表
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px"
           href="javascript:location.replace(location.href);" title="刷新">
            <i class="Hui-iconfont">&#xe68f;</i>
        </a>
    </nav>

    <form action="{{ route('admin.notice.index') }}">
        <input type="text" class="input-text" style="width:250px" placeholder="输入节点名称" name="name" value="">
        <button type="submit" class="btn btn-success radius"><i class="Hui-iconfont">&#xe665;</i> 搜索
        </button>
    </form>

    @include('admin.common.msg')

    <div class="page-container">
        <div class="cl pd-5 bg-1 bk-gray mt-20">
        <span class="l">
            {!! auth()->user()->addBtn('admin.notice.create') !!}
        </span>
        </div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-hover table-bg table-sort">
                <thead>
                <tr class="text-c">
                    <th width="30">ID</th>
                    <th width="60">房东</th>
                    <th width="60">租客</th>
                    <th width="80">预约时间</th>
                    <th width="120">内容</th>
                    <th width="40">状态</th>
                    <th width="100">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $item)
                    <tr class="text-c">
                        <td>{{ $item->id }} </td>
                        <td>{{ $item->owner->name }}</td>
                        <td> 租客->{{ $item->renting_id }} </td>
                        <td>{{ $item->book_time }}</td>
                        <td>{{ $item->cnt }}</td>
                        <td>{{ $item->status }}</td>
                        <td class="td-manage">
                            @if(auth()->user()->editBtn('admin.notice.edit'))
                                <a href="{{ route('admin.notice.edit',$item) }}"
                                   class="label label-success radius">修改</a>
                            @endif
                            @if(auth()->user()->delBtn('admin.notice.destroy'))
                                <a href="{{ route('admin.notice.destroy',$item) }}"
                                   class="label label-danger radius delbtn">删除</a>
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            {{ $data->links() }}
        </div>
    </div>
    <style type="text/css">
        #pull_right {
            text-align: center;
        }

        .pull-right {
            /*float: left!important;*/
        }

        .pagination {
            display: inline-block;
            padding-left: 0;
            margin: 20px 0;
            border-radius: 4px;
        }

        .pagination > li {
            display: inline;
        }

        .pagination > li > a,
        .pagination > li > span {
            position: relative;
            float: left;
            padding: 6px 12px;
            margin-left: -1px;
            line-height: 1.42857143;
            color: #428bca;
            text-decoration: none;
            background-color: #fff;
            border: 1px solid #ddd;
        }

        .pagination > li:first-child > a,
        .pagination > li:first-child > span {
            margin-left: 0;
            border-top-left-radius: 4px;
            border-bottom-left-radius: 4px;
        }

        .pagination > li:last-child > a,
        .pagination > li:last-child > span {
            border-top-right-radius: 4px;
            border-bottom-right-radius: 4px;
        }

        .pagination > li > a:hover,
        .pagination > li > span:hover,
        .pagination > li > a:focus,
        .pagination > li > span:focus {
            color: #2a6496;
            background-color: #eee;
            border-color: #ddd;
        }

        .pagination > .active > a,
        .pagination > .active > span,
        .pagination > .active > a:hover,
        .pagination > .active > span:hover,
        .pagination > .active > a:focus,
        .pagination > .active > span:focus {
            z-index: 2;
            color: #fff;
            cursor: default;
            background-color: #428bca;
            border-color: #428bca;
        }

        .pagination > .disabled > span,
        .pagination > .disabled > span:hover,
        .pagination > .disabled > span:focus,
        .pagination > .disabled > a,
        .pagination > .disabled > a:hover,
        .pagination > .disabled > a:focus {
            color: #777;
            cursor: not-allowed;
            background-color: #fff;
            border-color: #ddd;
        }

        .clear {
            clear: both;
        }
    </style>

@endsection
@section('js')
    <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
    <script type="text/javascript" src="/admin/lib/laypage/1.2/laypage.js"></script>
    <script type="text/javascript">
        // 生成一个token csrf
        const _token = "{{ csrf_token() }}";

        $('.delbtn').click(function (evt) {
            // 获取请求的url
            let url = $(this).attr('href');
            // 发起delete请求
            $.ajax({
                url,
                type: 'DELETE',
                data: {_token},
                dataType: 'json'
            }).then(({msg, status}) => {
                if (status == 200) {
                    $(this).closest('tr').remove();
                    layer.alert(msg, {time: 900, icon: 1});
                }
            });
            return false;
        });
    </script>
@endsection
